
package com.shop.cloud.mall.admin.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.shop.cloud.common.core.util.R;
import com.shop.cloud.common.log.annotation.SysLog;
import com.shop.cloud.mall.common.entity.VipUser;
import com.shop.cloud.mall.admin.service.VipUserService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;

/**
 * 会员用户
 *
 * @author
 * @date 2024-04-02 15:21:18
 */
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/vipuser")
@Tag(description = "vipuser", name = "会员用户管理")
public class VipUserController {

    private final VipUserService vipUserService;

    /**
     * 会员用户分页列表
     * @param page 分页对象
     * @param vipUser 会员用户
     * @return
     */
    @Operation(summary = "会员用户分页列表")
    @GetMapping("/page")
    @PreAuthorize("@ato.hasAuthority('mall:vipuser:index')")
    public R getPage(Page page, VipUser vipUser) {
        return R.ok(vipUserService.page2(page, vipUser));
    }

    /**
     * 会员用户查询
     * @param id
     * @return R
     */
    @Operation(summary = "会员用户查询")
    @GetMapping("/{id}")
    @PreAuthorize("@ato.hasAuthority('mall:vipuser:get')")
    public R getById(@PathVariable("id") String id) {
        return R.ok(vipUserService.getById(id));
    }

    /**
     * 会员用户新增
     * @param vipUser 会员用户
     * @return R
     */
    @Operation(summary = "会员用户新增")
    @SysLog("新增会员用户")
    @PostMapping
    @PreAuthorize("@ato.hasAuthority('mall:vipuser:add')")
    public R save(@RequestBody VipUser vipUser) {
        return R.ok(vipUserService.save(vipUser));
    }

    /**
     * 会员用户修改
     * @param vipUser 会员用户
     * @return R
     */
    @Operation(summary = "会员用户修改")
    @SysLog("修改会员用户")
    @PutMapping
    @PreAuthorize("@ato.hasAuthority('mall:vipuser:edit')")
    public R updateById(@RequestBody VipUser vipUser) {
        return R.ok(vipUserService.updateById(vipUser));
    }

    /**
     * 会员用户删除
     * @param id
     * @return R
     */
    @Operation(summary = "会员用户删除")
    @SysLog("删除会员用户")
    @DeleteMapping("/{id}")
    @PreAuthorize("@ato.hasAuthority('mall:vipuser:del')")
    public R removeById(@PathVariable String id) {
        return R.ok(vipUserService.removeById(id));
    }

}
